﻿
@{
    ViewBag.Title = "回收条码";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";

    var workshops = ViewBag.Workshops as List<IOA.MES.DataAccess.VModel.VWorkshop>;
}
@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WorkShop">车间：</label>
                        <div class="layui-input-inline">
                            <select id="selWorkshops">
                                @foreach (var item in workshops)
                                {
                                    <option value="@item.WorkshopCode">@item.WorkshopName</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.OrderNo">订单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtOrderNo" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WorkorderNo">工单号：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtWorkOrderNo" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.BarCode">组件条码：</label>
                        <div class="layui-input-inline">
                            <input type="text" id="txtBarCode" autocomplete="off" class="layui-input">
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <a id="btnExport" target="_blank" class="layui-btn layuiadmin-btn-list" href="javascript:void(0)">
                            <i class="layui-icon layui-icon-download-circle layuiadmin-button-btn"></i>
                        </a>
                        <button id="btnAdd" class="layui-btn layuiadmin-btn-list" type="button">
                            <i class="layui-icon layui-icon-addition layuiadmin-button-btn"></i>
                        </button>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });

        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['table', 'layer', 'form', 'laydate'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form;

                var options = {
                    elem: '#table'
                    , url: '/WorkOrder/QueryRecycleCompinents'
                    , method: "post"
                    , where: { workshopCode: "", orderNo: "", workOrderNo: "", barCode: "" }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: '序号', type: "numbers", width: 60, fixed: "left" }
                        , { field: 'BarCode', title: '组件条码', minWidth: 200, fixed: "left" }
                        , { field: 'OrderNo', title: '订单号', minWidth: 150 }
                        , { field: 'WorkOrderNo', title: '工单号', minWidth: 200 }
                        , { field: 'WorkshopName', title: '车间', minWidth: 100 }
                        , { field: 'ProductCode', title: '成品料号', minWidth: 150 }
                        , { field: 'ProductName', title: '成品名称', minWidth: 250 }
                        , { field: 'CNCreateBy', title: '回收人', minWidth: 100 }
                        , { field: 'CreateTimeStr', title: '回收时间', minWidth: 150 }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    options.where.workshopCode = $("#selWorkshops").val().trim();
                    options.where.orderNo = $("#txtOrderNo").val().trim();
                    options.where.workOrderNo = $("#txtWorkOrderNo").val().trim();
                    options.where.barCode = $("#txtBarCode").val().trim();
                    $("#btnExport").attr("href", "/WorkOrder/ExportRecycleCompinents?workshopCode=" + options.where.workshopCode + "&orderNo=" + options.where.orderNo + "&workOrderNo=" + options.where.workOrderNo + "&barCode=" + options.where.barCode);

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }

                $(document).on("click", "#btnAdd", function () {
                    layer.prompt({
                        title: '请输入要回收的条码',
                    }, function (value, index, elem) {
                        var loadId = layui.layer.load();
                        $.ajax({
                            url: "/WorkOrder/SubmitRecycle",
                            data: {
                                barCode: value
                            },
                            complete: function () {
                                layui.layer.close(loadId);
                            },
                            success: function (res) {
                                if (res.ErrCode != 200) {
                                    layui.layer.msg(res.ErrMsg, { icon: 5 });
                                    return;
                                }
                                layui.layer.msg("回收成功！", { icon: 6 });
                                queryTable();
                            }
                        });
                        layer.close(index);
                    });
                });
            });
        }
    </script>
}
